{extend name="layout" /}
{block name="content"}

<style type="text/css">
    .layui-card-body{
        background-color: #fff;
        padding: 10px;
        margin-top: 10px;
        border: 1px solid #e6e6e6;
    }

    .layui-tab-card>.layui-tab-title{
        background-color: #f9f9f9;
        border-bottom: none;
    }
    .layui-tab-content{
        padding: 0;
    }
    .layui-table, .layui-table-view{
        margin: 0;
    }
    .layui-margin-10{
        margin:10px ;
    }
    .layui-layer-page .layui-layer-content{
        overflow: initial;
    }
    /*.layui-table-cell {
        height: auto;
        text-overflow: inherit;
        overflow: visible;
        white-space: normal;
        word-wrap: break-word;
    }*/
</style>
<script src="__STATIC_JS__jquery.form.js" type="text/javascript" charset="utf-8"></script>

<form class="layui-form seller-form"  action="" >

    <div class="layui-form-item">
        <div class="layui-inline">
            <button type="button" class="layui-btn" id="appendix"><i class="layui-icon"></i>上传附件</button>
        </div>
    </div>
</form>

<div class="layui-card-body">
    <div class="layui-tab layui-tab-card" lay-filter="goods-tab" style="margin:0;">
        <div class="layui-tab-content" >
            <table id="Table" lay-filter="Table"></table>
        </div>
    </div>
</div>



<script>
    var table, window_box;
    layui.use(['form', 'layedit','upload', 'laydate','table','element'], function(){
        var upload = layui.upload;
        var element = layui.element;
        var filter = {};

        table = layui.table.render({
            elem: '#Table',
            height: 'full-181',
            cellMinWidth: '80',
            page: 'true',
            limit:'20',
            url: "{:url('Appendix/index')}?_ajax=1",
            id:'Table',
            cols: [[
                {type:'checkbox'},
                {field:'id', width:90, title:'ID', align: 'center'},
                {field:'operating',width:180,title:'操作', align: 'center',templet:function(data){
                        var html = '';

                        html += '<a class="layui-btn layui-btn-danger layui-btn-xs del-class" data-id="' + data.id + '">删除</a>';

                        html += '<a class="layui-btn layui-btn-xs copy-class" data-copyurl="' + data.copyurl + '">复制链接</a>';

                        return html;
                    }},
                {field:'name', width:300, title:'名字', align: 'center'},
                {field:'copyurl', width:300, title:'链接', align: 'center'},

                {field:'ctime', width:200, title:'创建时间', align: 'center'},

            ]]
        });

        /***
         * 上传附件
         * */
        upload.render({
            elem: '#appendix'
            ,url: "{:url('Files/uploadAppendixCopy')}"
            ,accept: 'file'
            ,before: function(obj){
                layer.load(1);
            }
            ,done: function(res){
                layer.closeAll('loading');
                layer.msg(res.msg);

                table.reload({
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
                return false;
            }
            ,error: function(res){
                layer.closeAll('loading');
                layer.msg("上传失败，请重新上传");
            }
        });

    });


    $(document).on('click', '.copy-class', function(){
        var copuurl = $(this).attr('data-copyurl');

        var save = function(e) {
            e.clipboardData.setData('text/plain', copuurl);
            e.preventDefault();
        };
        document.addEventListener('copy', save);
        document.execCommand('copy');
        document.removeEventListener('copy', save);
        console.log('复制成功');
        layer.msg("复制成功");
        return false;


    });


    //删除商品
    $(document).on('click', '.del-class', function(){
        var id = $(this).attr('data-id');
        layer.confirm('确认删除吗？', {
            title: '提示', btn: ['确认', '取消'] //按钮
        }, function(){
            delClass(id);
        });
    });

    //删除操作
    function delClass(id){
        JsPost('{:url("Appendix/del")}',{id:id},function(e){
            layer.msg(e.msg, {time: 1300}, function(){
                table.reload('Table');
            });
        });
    }



</script>
{/block}